<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="pojo.User" %>
<%@ page import="tools.Translator" %>
<%@ page import="utils.db.impl.DeviceFetcher" %>
<%@ page import="utils.db.impl.UserFetcher" %>
<%@ page import="java.util.List" %>
<%@ page import="pojo.Device" %>


<%
User user=(User)session.getAttribute("user");

%>
<script type="text/javascript" src="js/changeState.js"></script>
<%if (session.getAttribute("user") == null) {%>
<h1>Brak dostępu do tej strony!</h1>
<%}else{ 
	int id = user.getId();
%>

<div id="gallery_container">
	

    	

    <h1>Zmiana statusu naprawianych urządzeń</h1>
    <table style="width: 700px; ">
    <tr>
     <td style="width: 200px; height: 40px; text-align: center;"><b>Typ</b></td>
    <td style="width: 200px; height: 40px; text-align: center;"><b>Opis</b></td>
    <td style="width: 150px; height: 40px; text-align: center;"><b>Klient</b></td>
    <td style="width: 150px; height: 40px; text-align: center;"><b>Status</b></td>
    <td style="width: 150px; height: 40px; text-align: center;"><b>Działanie</b></td>
    </tr>
    <%
                                    DeviceFetcher fetcher = new DeviceFetcher();
                                    List<Device> devices = fetcher.getDevicesByIdServiceman(id);
                                   
                                    for(int i=0;i<devices.size();i++){
                                            UserFetcher u = new UserFetcher();
                                            User client = u.getUserById(devices.get(i).getClientId());
                                            String clientName = client.getFirstName();
                                            String clientSurname = client.getLastName();
                                    %>
    <tr>
     <td style="width: 200px; height: 40px; text-align: center;"><%=Translator.toPolish(String.valueOf(devices.get(i).getType()))%></td>
    <td style="width: 200px; height: 40px; text-align: center;"><%= devices.get(i).getDescription()%></td>
    <td style="width: 150px; height: 40px; text-align: center;"><%= clientName%> <%=clientSurname %></td>
    <td style="width: 150px; height: 40px; text-align: center;">
            <div class="styled-select2">
                    <select name="state[]" class="stateSelect">
                            <option value="0">Wybierz status...</option>
                            <option value="WAITING">Oczekuje </option>
                            <option value="INPROGRESS">W naprawie </option>
                            <option value="FIXED">Naprawione </option>
                    </select>
            </div>
    </td>
    <input type="hidden" class="deviceIdInput"  name="deviceId[]" value ='<%=devices.get(i).getId() %>'/>
     
    <td style="width: 150px; height: 40px; text-align: center;"><input type='submit' class='change' id='styled-button-12' value='Zmień status' /></td>
     
    </tr>
     
    <%} %>
    </table>
   <center><div id="res" class="res"></div></center>
    </div>
    <script type="text/javascript">
            $('.change').on('click', function(){new Report( this ).change();});
    </script>
    <%} %>







